libname in 'c:\local_c\bfeed3';

**for REStat paper, "Breastfeeding and Children's Early Cognitive Outcomes";
**bfeed08 data set is from the merge08 program, merges mother and child data;
**put the whole thing together and form variables;

data in.mns082;
set in.bfeed08;
**so let's just form the basic data set;
keep r0000100 c0000100 c0000200 cmob cyob pwhte
/*test scores and bf info.*/
bfeed bf14 bf512 bf1325 bf26p math56 read56
/*mother's/family characteristics*/
afqt cblack chisp hgcyob marbirth agebirth momfor bapt79 cath79 regne regnc regs regw
msmoke prenat1 home56 lninc56 sped
/*maternal employment*/
ptp ftp
pt12 ft12 pt13 ft13 pt52 ft52
pty2 fty2 pty3 fty3 pty4 fty4
hwk12a hwk13a hwk52a pwk12 pwk13 pwk52
hwky2a hwky3a hwky4a pwky2 pwky3 pwky4 
/*child's characteristics*/
cfemale border1 border2 bw55 csect gestlt35 gest3537 vage56
/*weight and missing dvs*/
custwt cwtfull sibwt
afqtdv bw55dv gestdv predv regdv homedv inc56dv speddv pftpdv pfty1dv pfty24dv
hy1adv ha24dv
/*for Der paper comparison*/
border gestwks bweight homec56 homee56 pov56 smokedv homecdv homeedv bwxdv gwdv pov56dv
/*for extra info. at end, experiment*/
pre56 hdst56 hdstdv marr56 sep56 div56 wid56 marrdv  sppa56 sppaw56 sppaed56 sppa56dv;

*breastfeeding duration dummy variables;
bf14 = .;
bf512 = .;
bf1325 = .;
bf26p = .;

if bfeed = 0 then bf14 = 0;
if bfeed = 0 then bf512 = 0;
if bfeed = 0 then bf1325 = 0;
if bfeed = 0 then bf26p = 0;

if (bfwk ge 1 and bfwk le 4) then bf14 = 1;
if (bfwk ge 1 and bfwk le 4) then bf512 = 0;
if (bfwk ge 1 and bfwk le 4) then bf1325 = 0;
if (bfwk ge 1 and bfwk le 4) then bf26p = 0;

if (bfwk ge 5 and bfwk le 12) then bf14 = 0;
if (bfwk ge 5 and bfwk le 12) then bf512 = 1;
if (bfwk ge 5 and bfwk le 12) then bf1325 = 0;
if (bfwk ge 5 and bfwk le 12) then bf26p = 0;

if (bfwk ge 13 and bfwk le 25) then bf14 = 0;
if (bfwk ge 13 and bfwk le 25) then bf512 = 0;
if (bfwk ge 13 and bfwk le 25) then bf1325 = 1;
if (bfwk ge 13 and bfwk le 25) then bf26p = 0;

if (bfwk ge 26) then bf14 = 0;
if (bfwk ge 26) then bf512 = 0;
if (bfwk ge 26) then bf1325 = 0;
if (bfwk ge 26) then bf26p = 1;

*standardize test scores to mean 0, s.d. 1.;
*since should be mean 100, s.d. 15, just do as follows;
read56 = (read56 - 100)/15;
math56 = (math56 - 100)/15;

*first born;
border1 = .;
if border = 1 then border1 = 1;
if border gt 1 then border1 = 0;
*second born;
border2 = .;
if border = 2 then border2 = 1;
if border gt 2 then border2 = 0;
if border = 1 then border2 = 0;

*region at birth;
regne = .;
regnc = .;
regs = .;
regw = .;
if region = 1 then do;
regne = 1;
regnc = 0;
regs = 0;
regw = 0;
end;
if region = 2 then do;
regne = 0;
regnc = 1;
regs = 0;
regw = 0;
end;
if region = 3 then do;
regne = 0;
regnc = 0;
regs = 1;
regw = 0;
end;
if region = 4 then do;
regne = 0;
regnc = 0;
regs = 0;
regw = 1;
end;

**if born before '79, will give you the '79 region (note just doing this for the full means
**comparison table;
if (cyob ge 1970 and cyob lt 1979) then do;
if reg79 = 1 then do;
regne = 1;
regnc = 0;
regs = 0;
regw = 0;
end;
if reg79 = 2 then do;
regne = 0;
regnc = 1;
regs = 0;
regw = 0;
end;
if reg79 = 3 then do;
regne = 0;
regnc = 0;
regs = 1;
regw = 0;
end;
if reg79 = 4 then do;
regne = 0;
regnc = 0;
regs = 0;
regw = 1;
end;
end;

**gestational weeks;
gestlt35 = .;
if (gestwks gt 0 and gestwks le 34) then gestlt35 = 1;
if gestwks ge 35 then gestlt35 = 0;

gest3537 = .;
if (gestwks gt 0 and gestwks le 34) then gest3537 = 0;
if (gestwks = 35 or gestwks = 36 or gestwks = 37) then gest3537 = 1;
if gestwks gt 37 then gest3537 = 0;

lninc56 = .;
if inc56 = 0 then inc56 = .000001;
lninc56 = log(inc56);

**now various measures of employment, note accounting for missings;
*percentage of weeks worked in 12 months prior to birth;
pwkp = .;
if (wksp03 = 0) then pwkp = wksp/52;
if (wksp03 = 1) then pwkp = wksp/51;
if (wksp03 = 2) then pwkp = wksp/50;
if (wksp03 = 3) then pwkp = wksp/49;
if (wksp03 = 4) then pwkp = wksp/48;
if (wksp03 = 5) then pwkp = wksp/47;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwkp = .;
if pwkp ne . then do;
if pwkp = 0 then hwkp = 0;
if pwkp = 0 then hwkpa = 0;
if (pwkp ne 0 and hrspn3 = 0) then hwkp = hrsp/wksp;
if (pwkp ne 0 and hrspn3 = 0 and wksp03 = 0) then hwkpa = hrsp/52;
if (pwkp ne 0 and hrspn3 = 0 and wksp03 = 1) then hwkpa = hrsp/51;
if (pwkp ne 0 and hrspn3 = 0 and wksp03 = 2) then hwkpa = hrsp/50;
if (pwkp ne 0 and hrspn3 = 0 and wksp03 = 3) then hwkpa = hrsp/49;
if (pwkp ne 0 and hrspn3 = 0 and wksp03 = 4) then hwkpa = hrsp/48;
if (pwkp ne 0 and hrspn3 = 0 and wksp03 = 5) then hwkpa = hrsp/47;
end;

**now year 1;
*percentage of weeks worked in year after birth;
pwky1 = .;
if (wksy103 = 0) then pwky1 = wksy1/52;
if (wksy103 = 1) then pwky1 = wksy1/51;
if (wksy103 = 2) then pwky1 = wksy1/50;
if (wksy103 = 3) then pwky1 = wksy1/49;
if (wksy103 = 4) then pwky1 = wksy1/48;
if (wksy103 = 5) then pwky1 = wksy1/47;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwky1 = .;
if pwky1 ne . then do;
if pwky1 = 0 then hwky1 = 0;
if pwky1 = 0 then hwky1a = 0;
if (pwky1 ne 0 and hrsy1n3 = 0) then hwky1 = hrsy1/wksy1;
if (pwky1 ne 0 and hrsy1n3 = 0 and wksy103 = 0) then hwky1a = hrsy1/52;
if (pwky1 ne 0 and hrsy1n3 = 0 and wksy103 = 1) then hwky1a = hrsy1/51;
if (pwky1 ne 0 and hrsy1n3 = 0 and wksy103 = 2) then hwky1a = hrsy1/50;
if (pwky1 ne 0 and hrsy1n3 = 0 and wksy103 = 3) then hwky1a = hrsy1/49;
if (pwky1 ne 0 and hrsy1n3 = 0 and wksy103 = 4) then hwky1a = hrsy1/48;
if (pwky1 ne 0 and hrsy1n3 = 0 and wksy103 = 5) then hwky1a = hrsy1/47;
end;

**now year 2;
*percentage of weeks worked in second year after birth;
pwky2 = .;
if (wksy203 = 0) then pwky2 = wksy2/52;
if (wksy203 = 1) then pwky2 = wksy2/51;
if (wksy203 = 2) then pwky2 = wksy2/50;
if (wksy203 = 3) then pwky2 = wksy2/49;
if (wksy203 = 4) then pwky2 = wksy2/48;
if (wksy203 = 5) then pwky2 = wksy2/47;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwky2 = .;
if pwky2 ne . then do;
if pwky2 = 0 then hwky2 = 0;
if pwky2 = 0 then hwky2a = 0;
if (pwky2 ne 0 and hrsy2n3 = 0) then hwky2 = hrsy2/wksy2;
if (pwky2 ne 0 and hrsy2n3 = 0 and wksy203 = 0) then hwky2a = hrsy2/52;
if (pwky2 ne 0 and hrsy2n3 = 0 and wksy203 = 1) then hwky2a = hrsy2/51;
if (pwky2 ne 0 and hrsy2n3 = 0 and wksy203 = 2) then hwky2a = hrsy2/50;
if (pwky2 ne 0 and hrsy2n3 = 0 and wksy203 = 3) then hwky2a = hrsy2/49;
if (pwky2 ne 0 and hrsy2n3 = 0 and wksy203 = 4) then hwky2a = hrsy2/48;
if (pwky2 ne 0 and hrsy2n3 = 0 and wksy203 = 5) then hwky2a = hrsy2/47;
end;

**now year 3;
*percentage of weeks worked in third year after birth;
pwky3 = .;
if (wksy303 = 0) then pwky3 = wksy3/52;
if (wksy303 = 1) then pwky3 = wksy3/51;
if (wksy303 = 2) then pwky3 = wksy3/50;
if (wksy303 = 3) then pwky3 = wksy3/49;
if (wksy303 = 4) then pwky3 = wksy3/48;
if (wksy303 = 5) then pwky3 = wksy3/47;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwky3 = .;
if pwky3 ne . then do;
if pwky3 = 0 then hwky3 = 0;
if pwky3 = 0 then hwky3a = 0;
if (pwky3 ne 0 and hrsy3n3 = 0) then hwky3 = hrsy3/wksy3;
if (pwky3 ne 0 and hrsy3n3 = 0 and wksy303 = 0) then hwky3a = hrsy3/52;
if (pwky3 ne 0 and hrsy3n3 = 0 and wksy303 = 1) then hwky3a = hrsy3/51;
if (pwky3 ne 0 and hrsy3n3 = 0 and wksy303 = 2) then hwky3a = hrsy3/50;
if (pwky3 ne 0 and hrsy3n3 = 0 and wksy303 = 3) then hwky3a = hrsy3/49;
if (pwky3 ne 0 and hrsy3n3 = 0 and wksy303 = 4) then hwky3a = hrsy3/48;
if (pwky3 ne 0 and hrsy3n3 = 0 and wksy303 = 5) then hwky3a = hrsy3/47;
end;

**now year 4;
*percentage of weeks worked in fourth year after birth;
pwky4 = .;
if (wksy403 = 0) then pwky4 = wksy4/52;
if (wksy403 = 1) then pwky4 = wksy4/51;
if (wksy403 = 2) then pwky4 = wksy4/50;
if (wksy403 = 3) then pwky4 = wksy4/49;
if (wksy403 = 4) then pwky4 = wksy4/48;
if (wksy403 = 5) then pwky4 = wksy4/47;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwky4 = .;
if pwky4 ne . then do;
if pwky4 = 0 then hwky4 = 0;
if pwky4 = 0 then hwky4a = 0;
if (pwky4 ne 0 and hrsy4n3 = 0) then hwky4 = hrsy4/wksy4;
if (pwky4 ne 0 and hrsy4n3 = 0 and wksy403 = 0) then hwky4a = hrsy4/52;
if (pwky4 ne 0 and hrsy4n3 = 0 and wksy403 = 1) then hwky4a = hrsy4/51;
if (pwky4 ne 0 and hrsy4n3 = 0 and wksy403 = 2) then hwky4a = hrsy4/50;
if (pwky4 ne 0 and hrsy4n3 = 0 and wksy403 = 3) then hwky4a = hrsy4/49;
if (pwky4 ne 0 and hrsy4n3 = 0 and wksy403 = 4) then hwky4a = hrsy4/48;
if (pwky4 ne 0 and hrsy4n3 = 0 and wksy403 = 5) then hwky4a = hrsy4/47;
end;

**now first 12 weeks;
*percentage of weeks worked in first 12 weeks after birth;
pwk12 = .;
if (wks1203 = 0) then pwk12 = wks12/12;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwk12 = .;
if pwk12 ne . then do;
if pwk12 = 0 then hwk12 = 0;
if pwk12 = 0 then hwk12a = 0;
if (pwk12 ne 0 and hrs12n3 = 0) then hwk12 = hrs12/wks12;
if (pwk12 ne 0 and hrs12n3 = 0 and wks1203 = 0) then hwk12a = hrs12/12;
end;

**now next 14 weeks;
*percentage of weeks worked in next 14 weeks after birth;
pwk13 = .;
if (wks1303 = 0) then pwk13 = wks13/14;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwk13 = .;
if pwk13 ne . then do;
if pwk13 = 0 then hwk13 = 0;
if pwk13 = 0 then hwk13a = 0;
if (pwk13 ne 0 and hrs13n3 = 0) then hwk13 = hrs13/wks13;
if (pwk13 ne 0 and hrs13n3 = 0 and wks1303 = 0) then hwk13a = hrs13/14;
end;

**now first 26 weeks;
*percentage of weeks worked in first 26 weeks after birth;
pwk26 = .;
if (wks2603 = 0) then pwk26 = wks26/26;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwk26 = .;
if pwk26 ne . then do;
if pwk26 = 0 then hwk26 = 0;
if pwk26 = 0 then hwk26a = 0;
if (pwk26 ne 0 and hrs26n3 = 0) then hwk26 = hrs26/wks26;
if (pwk26 ne 0 and hrs26n3 = 0 and wks2603 = 0) then hwk26a = hrs26/26;
end;

**now second 26 weeks;
*percentage of weeks worked in second 26 weeks after birth;
pwk52 = .;
if (wks5203 = 0) then pwk52 = wks52/26;

*hours per week, with a at end, means divided over all weeks, without a, just averaged;
*over weeks worked;
hwk52 = .;
if pwk52 ne . then do;
if pwk52 = 0 then hwk52 = 0;
if pwk52 = 0 then hwk52a = 0;
if (pwk52 ne 0 and hrs52n3 = 0) then hwk52 = hrs52/wks52;
if (pwk52 ne 0 and hrs52n3 = 0 and wks5203 = 0) then hwk52a = hrs52/26;
end;

**okay, let's try to define ft pt in year prior to birth;
ptp = .;
ftp = .;
if (pwkp ge 0 and pwkp lt .25) then ptp = 0;
if (pwkp ge 0 and pwkp lt .25) then ftp = 0;
if ((pwkp ge .25) and (hwkp gt 0 and hwkp lt 30)) then ptp = 1; 
if ((pwkp ge .25) and (hwkp gt 0 and hwkp lt 30)) then ftp = 0; 
if ((pwkp ge .25) and (hwkp ge 30)) then ptp = 0; 
if ((pwkp ge .25) and (hwkp ge 30)) then ftp = 1; 

**now through first year intervals;
pt12 = .;
ft12 = .;
if (pwk12 ge 0 and pwk12 lt .25) then pt12 = 0;
if (pwk12 ge 0 and pwk12 lt .25) then ft12 = 0;
if ((pwk12 ge .25) and (hwk12 gt 0 and hwk12 lt 30)) then pt12 = 1; 
if ((pwk12 ge .25) and (hwk12 gt 0 and hwk12 lt 30)) then ft12 = 0; 
if ((pwk12 ge .25) and (hwk12 ge 30)) then pt12 = 0; 
if ((pwk12 ge .25) and (hwk12 ge 30)) then ft12 = 1; 

pt13 = .;
ft13 = .;
if (pwk13 ge 0 and pwk13 lt .25) then pt13 = 0;
if (pwk13 ge 0 and pwk13 lt .25) then ft13 = 0;
if ((pwk13 ge .25) and (hwk13 gt 0 and hwk13 lt 30)) then pt13 = 1; 
if ((pwk13 ge .25) and (hwk13 gt 0 and hwk13 lt 30)) then ft13 = 0; 
if ((pwk13 ge .25) and (hwk13 ge 30)) then pt13 = 0; 
if ((pwk13 ge .25) and (hwk13 ge 30)) then ft13 = 1; 

pt26 = .;
ft26 = .;
if (pwk26 ge 0 and pwk26 lt .25) then pt26 = 0;
if (pwk26 ge 0 and pwk26 lt .25) then ft26 = 0;
if ((pwk26 ge .25) and (hwk26 gt 0 and hwk26 lt 30)) then pt26 = 1; 
if ((pwk26 ge .25) and (hwk26 gt 0 and hwk26 lt 30)) then ft26 = 0; 
if ((pwk26 ge .25) and (hwk26 ge 30)) then pt26 = 0; 
if ((pwk26 ge .25) and (hwk26 ge 30)) then ft26 = 1; 

pt52 = .;
ft52 = .;
if (pwk52 ge 0 and pwk52 lt .25) then pt52 = 0;
if (pwk52 ge 0 and pwk52 lt .25) then ft52 = 0;
if ((pwk52 ge .25) and (hwk52 gt 0 and hwk52 lt 30)) then pt52 = 1; 
if ((pwk52 ge .25) and (hwk52 gt 0 and hwk52 lt 30)) then ft52 = 0; 
if ((pwk52 ge .25) and (hwk52 ge 30)) then pt52 = 0; 
if ((pwk52 ge .25) and (hwk52 ge 30)) then ft52 = 1; 

**then years 1 through 4;
pty1 = .;
fty1 = .;
if (pwky1 ge 0 and pwky1 lt .25) then pty1 = 0;
if (pwky1 ge 0 and pwky1 lt .25) then fty1 = 0;
if ((pwky1 ge .25) and (hwky1 gt 0 and hwky1 lt 30)) then pty1 = 1; 
if ((pwky1 ge .25) and (hwky1 gt 0 and hwky1 lt 30)) then fty1 = 0; 
if ((pwky1 ge .25) and (hwky1 ge 30)) then pty1 = 0; 
if ((pwky1 ge .25) and (hwky1 ge 30)) then fty1 = 1; 
pty2 = .;
fty2 = .;
if (pwky2 ge 0 and pwky2 lt .25) then pty2 = 0;
if (pwky2 ge 0 and pwky2 lt .25) then fty2 = 0;
if ((pwky2 ge .25) and (hwky2 gt 0 and hwky2 lt 30)) then pty2 = 1; 
if ((pwky2 ge .25) and (hwky2 gt 0 and hwky2 lt 30)) then fty2 = 0; 
if ((pwky2 ge .25) and (hwky2 ge 30)) then pty2 = 0; 
if ((pwky2 ge .25) and (hwky2 ge 30)) then fty2 = 1; 
pty3 = .;
fty3 = .;
if (pwky3 ge 0 and pwky3 lt .25) then pty3 = 0;
if (pwky3 ge 0 and pwky3 lt .25) then fty3 = 0;
if ((pwky3 ge .25) and (hwky3 gt 0 and hwky3 lt 30)) then pty3 = 1; 
if ((pwky3 ge .25) and (hwky3 gt 0 and hwky3 lt 30)) then fty3 = 0; 
if ((pwky3 ge .25) and (hwky3 ge 30)) then pty3 = 0; 
if ((pwky3 ge .25) and (hwky3 ge 30)) then fty3 = 1; 
pty4 = .;
fty4 = .;
if (pwky4 ge 0 and pwky4 lt .25) then pty4 = 0;
if (pwky4 ge 0 and pwky4 lt .25) then fty4 = 0;
if ((pwky4 ge .25) and (hwky4 gt 0 and hwky4 lt 30)) then pty4 = 1; 
if ((pwky4 ge .25) and (hwky4 gt 0 and hwky4 lt 30)) then fty4 = 0; 
if ((pwky4 ge .25) and (hwky4 ge 30)) then pty4 = 0; 
if ((pwky4 ge .25) and (hwky4 ge 30)) then fty4 = 1; 

**identify oversample of poor white;
pwhte = 0;
if r0173600 = 12 then pwhte = 1;

**dummy variables;
afqtdv = 0;
if afqt = . then afqtdv = 1;
if afqtdv = 1 then afqt = .;

bw55dv = 0;
if bw55 = . then bw55dv = 1;
if bw55dv = 1 then bw55 = .;

gestdv = 0;
if gestlt35 = . then gestdv = 1;
if gestdv = 1 then do;
gestlt35 = .;
gest3537 = .;
end;

predv = 0;
if (prenat1 = . or msmoke = . or csect = .) then predv = 1;
if predv = 1 then prenat1 = .;
if predv = 1 then msmoke = .;
if predv = 1 then csect = .;

regdv = 0;
if (region = .) then regdv = 1;
if regdv = 1 then regne = .;
if regdv = 1 then regnc = .;
if regdv = 1 then regs = .;
if regdv = 1 then regw = .;

homedv = 0;
if home56 = . then homedv = 1;
if homedv = 1 then home56 = .;

inc56dv = 0;
if lninc56 = . then inc56dv = 1;
if inc56dv = 1 then lninc56 = .;

**missing father/spouse ed. information;
speddv = 0;
if (sped = . and marbirth = 1) then speddv = 1;
if speddv = 1 then do;
sped = .;
end;

**employment dummy variables;
pftpdv = 0;
if ptp = . then pftpdv = 1;
if pftpdv = 1 then do;
ptp = .;
ftp = .;
end;

pfty1dv = 0;
if (pt12 = . or pt13 = . or pt52 = .) then pfty1dv = 1;
if pfty1dv = 1 then do;
pt12 = .;
ft12 = .;
pt13 = .;
ft13 = .;
pt52 = .;
ft52 = .;
end;

pfty24dv = 0;
if (pty2 = . or fty2 = . or pty3 = . or fty3 = . 
         or pty4 = . or fty4 = .) then pfty24dv = 1;
if pfty24dv = 1 then do;
   pty2 = .;
   fty2 = .;
   pty3 = .;
   fty3 = .;
   pty4 = .;
   fty4 = .;
end;

hy1adv = 0;
if (hwk12a =. or hwk13a = . or hwk52a = .) then hy1adv = 1;
if hy1adv = 1 then do;
hwk12a = .;
hwk13a = .;
hwk52a = .;
pwk12 = .;
pwk13 = .;
pwk52 = .;
end;

ha24dv = 0;
if (hwky2a = . or hwky3a = . or hwky4a = .) then ha24dv = 1;
if ha24dv = 1 then do;
hwky2a = .;
hwky3a = .;
hwky4a = .;
pwky2 = .;
pwky3 = .;
pwky4 = .;
end;

**dummy variables for additional variables at end exp;
hdstdv = 0;
if (pre56 = . or hdst56 = .) then hdstdv = 1;
if hdstdv = 1 then do;
pre56 = .;
hdst56 = .;
end;

**detailed marital status at age 5/6 interview and dummy variable for missing;
marr56 = .;
sep56 = .;
div56 = .;
wid56 = .;
if mar56 = 0 then do;
marr56 = 0;
sep56 = 0;
div56 = 0;
wid56 = 0;
end;
if mar56 = 1 then do;
marr56 = 1;
sep56 = 0;
div56 = 0;
wid56 = 0;
end;
if mar56 = 2 then do;
marr56 = 0;
sep56 = 1;
div56 = 0;
wid56 = 0;
end;
if mar56 = 3 then do;
marr56 = 0;
sep56 = 0;
div56 = 1;
wid56 = 0;
end;
if mar56 = 6 then do;
marr56 = 0;
sep56 = 0;
div56 = 0;
wid56 = 1;
end;

marrdv = 0;
if mar56 = . then marrdv = 1;

**spouse/partner info., experiment at end;
sppa56 = 0;
if sp56 = 1 or pa56 = 1 then sppa56 = 1;

sppaw56 = .;
sppaed56 = .;
if (sppa56 = 1) then do;
   if spw56 ne . then sppaw56 = spw56;
   if paw56 ne . then sppaw56 = paw56;
   if sped56 ge 0 and sped56 lt 25 then sppaed56 = sped56;
   if paed56 ge 0 and paed56 lt 25 then sppaed56 = paed56;
end;
*I'm going to fill in 0s here;
if sppa56 = 0 then sppaw56 = 0;
if sppa56 = 0 then sppaed56 = 0;

*now missings;
sppa56dv = 0;
if sppaw56 = . then sppa56dv = 1;
if sppaed56 = . then sppa56dv = 1;
if sppa56dv = 1 then do;
sppaw56 = .;
sppaed56 = .;
end;

**dummy variables for comparison with Der paper;
pov56dv = 0;
if pov56 = . then pov56dv = 1;
if pov56dv = 1 then pov56 = .;

homecdv = 0;
homeedv = 0;
if homec56 = . then homecdv = 1;
if homecdv = 1 then homec56 = .;
if homee56 = . then homeedv = 1;
if homeedv = 1 then homee56 = .;

*dummy variable for smoking for Der et al.;
smokedv = 0;
if msmoke = . then smokedv = 1;
if smokedv = 1 then msmoke = .;

*also for Der paper;
bwxdv = 0;
gwdv = 0;
if bweight = . then bwxdv = 1;
if bwxdv = 1 then bweight = .;
**convert ounces to grams;
bweight = bweight*28.349;

if gestwks = . then gwdv = 1;
if gwdv = 1 then gestwks = .;

**limiting the sample;
if bfeed ne .;
if bf14 ne .;
if math56 ne .;
**only lose a small number with these additional restrictions;
if cyob ge 1979;
if marbirth ne .;
if cath79 ne .;

proc means;
run;
